﻿<%@ Page Language="C#" MasterPageFile="~/Search/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Search_Scores_Default" Title="无标题页" %>

<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<ext:TokenScript ID="TokenScript1" runat="server">
        <script type="text/javascript">
            var applyFilter = function () {
                #{Store1}.filterBy(getRecordFilter());
            }
            
            var clearFilter = function () {
                #{CompanyIDFilter}.reset();
                #{CompanyNameFilter}.reset();
                #{ElectricNameFilter}.reset();                 
                #{TradeNameFilter}.reset();
                #{CreditFilter}.reset();
                #{usernameFilter}.reset();
                #{DeptNameFilter}.reset();
                #{ScoresFilter}.reset();
                #{Store1}.clearFilter();
            }

            var filterString = function (value, dataIndex, record) {
                var val = record.get(dataIndex);
                if (typeof val != "string") {
                    return value.length == 0;
                }
                return val.toLowerCase().indexOf(value.toLowerCase()) > -1;
            }

            var filterDate = function (value, dataIndex, record) {
                var val = record.get(dataIndex).clearTime(true).getTime();

                if (!Ext.isEmpty(value, false) && val != value.clearTime(true).getTime()) {
                    return false;
                }
                return true;
            }

            var filterNumber = function (value, dataIndex, record) {
                var val = record.get(dataIndex);			    

                if (!Ext.isEmpty(value, false) && val != value) {
                    return false;
                }
                return true;
            }

            var getRecordFilter = function () {
                var f = [];

                f.push({
                    filter: function(record) {                         
                        return filterString(#{CompanyIDFilter}.getValue(), 'CompanyID', record);
                    }
                });
                f.push({
                    filter: function(record) {                         
                        return filterString(#{CompanyNameFilter}.getValue(), 'CompanyName', record);
                    }
                });
                f.push({
                    filter: function(record) {                         
                        return filterString(#{ElectricNameFilter}.getValue(), 'ElectricName', record);
                    }
                }); 
                f.push({
                    filter: function(record) {                         
                        return filterString(#{TradeNameFilter}.getValue(), 'TradeName', record);
                    }
                });
                f.push({
                    filter: function(record) {                         
                        return filterNumber(#{ScoresFilter}.getValue(), 'Scores_now', record);
                    }
                });
                f.push({
                    filter: function(record) {                         
                        return filterString(#{CreditFilter}.getValue(), 'Credit', record);
                    }
                });
                f.push({
                    filter: function(record) {                         
                        return filterString(#{usernameFilter}.getValue(), 'username', record);
                    }
                });
                f.push({
                    filter: function(record) {                         
                        return filterString(#{DeptNameFilter}.getValue(), 'DeptName', record);
                    }
                });

                var len = f.length;
                return function(record) {
                    for (var i = 0; i < len; i++) {
                        if (!f[i].filter(record)) {
                            return false;
                        }
                    }
                    return true;
                };
            }  
        </script> </ext:TokenScript>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CXDB %>" 
        SelectCommand="SELECT [CompanyID], [CompanyName], [CompanyAddress], [ElectricName], [TradeName], [Scores_now], [Credit], [username], [DeptName], [Guid] FROM [vw_company_scores_groupby] WHERE ([Status] = @Status) ORDER BY [inTime] DESC">
        <SelectParameters>
            <asp:Parameter DefaultValue="1" Name="Status" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <ext:Store ID="Store1"  DataSourceID="SqlDataSource1" runat="server">
        <Reader>
            <ext:JsonReader ReaderID="Guid">
                <Fields>
                    <ext:RecordField Name="CompanyID" Type="String"></ext:RecordField>
                    <ext:RecordField Name="CompanyName" Type="String"></ext:RecordField> 
                    <ext:RecordField Name="ElectricName" Type="String"></ext:RecordField>
                    <ext:RecordField Name="TradeName" Type="String"></ext:RecordField>
                    <ext:RecordField Name="Scores_now" Type="Int"></ext:RecordField>
                    <ext:RecordField Name="Credit" Type="String"></ext:RecordField>
                    <ext:RecordField Name="username" Type="String"></ext:RecordField>
                    <ext:RecordField Name="DeptName" Type="String"></ext:RecordField>
                    <ext:RecordField Name="Guid" Type="String"></ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
        <AutoLoadParams>
            <ext:Parameter Name="start" Mode="Raw" Value="0" />
            <ext:Parameter Name="limit" Mode="raw" Value="20" />
        </AutoLoadParams> 
    </ext:Store>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CXDB %>" 
        SelectCommand="SELECT [ElectricID], [ElectricName] FROM [CX_Company_Sys_Electric]"></asp:SqlDataSource>
    <ext:Store ID="Store2" DataSourceID="SqlDataSource2" runat="server">
        <Reader>
            <ext:JsonReader>
                <Fields>
                    <ext:RecordField Name="ElectricID" Type="Int"></ext:RecordField>
                    <ext:RecordField Name="ElectricName" Type="String"></ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CXDB %>" 
        SelectCommand="SELECT [TradeID], [TradeName] FROM [CX_Company_Sys_Trade]"></asp:SqlDataSource>
    <ext:Store ID="Store3" DataSourceID="SqlDataSource3" runat="server">
        <Reader>
            <ext:JsonReader>
                <Fields>
                    <ext:RecordField Name="TradeID" Type="Int"></ext:RecordField>
                    <ext:RecordField Name="TradeName" Type="String"></ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
        
    <ext:GridPanel ID="GridPanel1" StoreID="Store1"  TrackMouseOver="true" runat="server">
        <ColumnModel>
            <Columns>
                <ext:Column DataIndex="CompanyID" Header="户号"></ext:Column>
                <ext:Column DataIndex="CompanyName" Header="户名"></ext:Column> 
                <ext:Column DataIndex="ElectricName" Header="用电类型"></ext:Column>
                <ext:Column DataIndex="TradeName" Header="行业类别"></ext:Column>
                <ext:Column DataIndex="Scores_now" Header="积分"></ext:Column>
                <ext:Column DataIndex="Credit" Header="信誉级别"></ext:Column>
                <ext:Column DataIndex="username" Header="提交人"></ext:Column>
                <ext:Column DataIndex="DeptName" Header="提交人部门"></ext:Column>
                <ext:Column Width="28" DataIndex="Guid" Sortable="false" MenuDisabled="true" Header="&nbsp;" Fixed="true">
                    <Renderer Handler="return '';" />
                </ext:Column>
                 <ext:CommandColumn ColumnID="Apply" Header="申请">
                        <Commands>
                            <ext:GridCommand CommandName="Apply" Icon="ApplicationGet" >
                                <ToolTip  Text="申请查询"/>
                            </ext:GridCommand>
                        </Commands>
                    </ext:CommandColumn>
            </Columns> 
        </ColumnModel>
        <AjaxEvents>
                <Command OnEvent="ApplySub">
                
                    <ExtraParams>
                        <ext:Parameter Name="id" Value="record.data.Guid" Mode="Raw">
                        </ext:Parameter> 
                    </ExtraParams>
                </Command>
             </AjaxEvents>
        <View>
            <ext:GridView ID="GridView1" runat="server">
                <HeaderRows>
                    <ext:HeaderRow>
                        <Columns>
                            <ext:HeaderColumn  Cls="x-small-editor">
                                <Component>
                                    <ext:TextField ID="CompanyIDFilter" runat="server" EnableKeyEvents="true">
                                        <Listeners>
                                            <KeyUp Handler="applyFilter();" Buffer="250" />                                                
                                        </Listeners>
                                    </ext:TextField>
                                </Component>
                            </ext:HeaderColumn>
                            <ext:HeaderColumn  Cls="x-small-editor">
                                <Component>
                                    <ext:TextField ID="CompanyNameFilter" runat="server" EnableKeyEvents="true">
                                        <Listeners>
                                            <KeyUp Handler="applyFilter();" Buffer="250" />                                                
                                        </Listeners>
                                    </ext:TextField>
                                </Component>
                            </ext:HeaderColumn>
                            <ext:HeaderColumn Cls="x-small-editor">
                                <Component>
                                    <ext:ComboBox ID="ElectricNameFilter" runat="server" 
                                        StoreID="Store2"
                                        TriggerAction="All"
                                        Mode="Local"
                                        DisplayField="ElectricName"
                                        ValueField="ElectricName">    
                                        <Listeners>
                                            <Select Handler="applyFilter();" />
                                        </Listeners>     
                                    </ext:ComboBox>
                                </Component>
                            </ext:HeaderColumn>
                            <ext:HeaderColumn Cls="x-small-editor">
                                <Component>
                                    <ext:ComboBox ID="TradeNameFilter" runat="server" 
                                        StoreID="Store3"
                                        TriggerAction="All"
                                        Mode="Local"
                                        DisplayField="TradeName"
                                        ValueField="TradeName">    
                                        <Listeners>
                                            <Select Handler="applyFilter();" />
                                        </Listeners>     
                                    </ext:ComboBox>
                                </Component>
                            </ext:HeaderColumn>
                            <ext:HeaderColumn  Cls="x-small-editor">
                                <Component>
                                    <ext:TextField ID="ScoresFilter" runat="server" EnableKeyEvents="true">
                                        <Listeners>
                                            <KeyUp Handler="applyFilter();" Buffer="250" />                                                
                                        </Listeners>
                                    </ext:TextField>
                                </Component>
                            </ext:HeaderColumn>
                            <ext:HeaderColumn  Cls="x-small-editor">
                                <Component>
                                    <ext:TextField ID="CreditFilter" runat="server" EnableKeyEvents="true">
                                        <Listeners>
                                            <KeyUp Handler="applyFilter();" Buffer="250" />                                                
                                        </Listeners>
                                    </ext:TextField>
                                </Component>
                            </ext:HeaderColumn>
                            <ext:HeaderColumn  Cls="x-small-editor">
                                <Component>
                                    <ext:TextField ID="usernameFilter" runat="server" EnableKeyEvents="true">
                                        <Listeners>
                                            <KeyUp Handler="applyFilter();" Buffer="250" />                                                
                                        </Listeners>
                                    </ext:TextField>
                                </Component>
                            </ext:HeaderColumn>
                            <ext:HeaderColumn Cls="x-small-editor">
                                <Component>
                                    <ext:ComboBox ID="DeptNameFilter" runat="server"  
                                        TriggerAction="All"
                                        Mode="Local" >    
                                        <Items>
                                            <ext:ListItem Text="大客户组" Value="大客户组" />
                                            <ext:ListItem Text="秀山供电所" Value="秀山供电所" />
                                            <ext:ListItem Text="四街供电所" Value="四街供电所" />
                                            <ext:ListItem Text="九街供电所" Value="九街供电所" />
                                            <ext:ListItem Text="河西供电所" Value="河西供电所" />
                                            <ext:ListItem Text="杨广供电所" Value="杨广供电所" />
                                            <ext:ListItem Text="高大供电所" Value="高大供电所" />
                                            
                                        </Items>
                                        <Listeners>
                                            <Select Handler="applyFilter();" />
                                        </Listeners>     
                                    </ext:ComboBox>
                                </Component>
                            </ext:HeaderColumn>
                           <ext:HeaderColumn AutoWidthElement="false">
                                <Component>
                                    <ext:Button ID="ClearFilterButton" runat="server" Icon="Cancel">
                                        <ToolTips>
                                            <ext:ToolTip ID="ToolTip1" runat="server" Html="清空选择" />
                                        </ToolTips>
                                        
                                        <Listeners>
                                            <Click Handler="clearFilter();" />
                                        </Listeners>                                            
                                    </ext:Button>
                                </Component>
                            </ext:HeaderColumn>  
                        </Columns>
                    </ext:HeaderRow>
                </HeaderRows>
            </ext:GridView>
        </View>
         <BottomBar>
            <ext:PagingToolBar 
                ID="PagingToolBar1" 
                runat="server" 
                PageSize="10" 
                StoreID="Store1" 
                />
        </BottomBar>
    </ext:GridPanel>
     <ext:Window ID="Window1"  Modal="true"  Width="200" Height="150" Closable="false" runat="server" Resizable="false" ShowOnLoad="false" Collapsible="false" Icon="BuildingGo" Title="查询申请:原因">
        <Body>
            <ext:FormPanel runat="server" ID="ApplyForm">
                <Body>
                <ext:ContainerLayout runat="server" ID="containter">
                    <ext:Panel ID="Panel2" runat="server" >
                        <Body>
                        <table style="width:100%">
                            <tr>
                                <td>
                                <ext:Hidden ID="tfhiddenid" runat="server" ></ext:Hidden>
                                <ext:TextArea runat="server" Width="180" ID="tfreason"></ext:TextArea>
                                </td>
                            </tr>
                        </table> 
                        </Body>
                    </ext:Panel>
                </ext:ContainerLayout>
                </Body>
                <Buttons>
                    <ext:Button runat="server" ID="SubApply" Text="提交">
                        <AjaxEvents>
                            <Click OnEvent="Sub">                        
                            </Click>
                        </AjaxEvents>
                    </ext:Button>
                    <ext:Button runat="server" ID="Button1" Text="撤销">
                        <AjaxEvents>
                            <Click OnEvent="Cancel">                        
                            </Click>
                        </AjaxEvents>
                    </ext:Button>
                </Buttons>
            </ext:FormPanel>
        </Body>
    </ext:Window>
</asp:Content>

